<template>
  <el-button
    @click="handleDelete"
    size="mini"
    type="text"
  >{{ $language.local("删除") }}</el-button>
</template>

<script>
export default {
  inject: ["reload"],
  props: {
    api: String,
    row: Object,
  },
  methods: {
    async handleDelete() {
      let result = await this.$confirm(
        `${this.$language.local(
          "此操作将会删除该行数据，请谨慎操作，是否继续"
        )}？`,
        this.$language.local("提示"),
        {
          confirmButtonText: this.$language.local("确定"),
          cancelButtonText: this.$language.local("取消"),
          type: "warning",
        }
      ).catch((err) => err);

      if (result === "confirm") {
        let id = this.row["id"] || this.row["ID"] || this.row["Id"];
        await this.$http.delete(this.api + id, {
          mid: this.row.MID,
        });

        this.reload();
      } else {
        this.$message.info("已取消");
      }
    },
  },
};
</script>

<style></style>
